import request from '@/utils/request';
import type {
  BaseResponse,
  // 角色管理
  RoleListItem,
  AddRoleParams,
  EditRoleParams,
  DeleteRoleParams,
  // 账号（用户）管理
  AddAdminUserParams,
  ViewAdminUserParams,
  ViewAdminUserResponseData,
  DeleteUserParams,
  ChangeUserStatusParams,
  GetAdminListByPageParams,
  GetAdminListByPageResponseData,
  UserDropdownItem,
  EditAdminUserParams,
  // 当前登录用户信息
  GetLoginUserInfoResponseData,
  EditLoginUserInfoParams,
  FormDataParams
} from './model/model';

// ---------------------- 角色管理 ----------------------

// 管-角色-列表
export const getRoleList = () =>
  request.post<BaseResponse<RoleListItem[]>>('/role/getRoleList');

// 管-角色-添加
export const addRole = (params: AddRoleParams) =>
  request.post<BaseResponse<null>>('/role/addRole', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-角色-编辑
export const editRole = (params: EditRoleParams) =>
  request.post<BaseResponse<null>>('/role/editRole', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-角色-删除
export const deleteRole = (params: DeleteRoleParams) =>
  request.post<BaseResponse<null>>('/role/deleteRole', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-角色-下拉列表
export const getRoleDropdownList = () =>
  request.post<BaseResponse<RoleListItem[]>>('/role/getRoleDropdownList');

// 管-角色-查看
export const viewRole = (params: { id: string }) =>
  request.post<BaseResponse<{
    id: number;
    roleName: string;
    type: string;
    permissionCode: string[];
  }>>('/role/viewRole', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// ---------------------- 账号（用户）管理 ----------------------

// 管-账号-添加
export const addAdminUser = (params: AddAdminUserParams) =>
  request.post<BaseResponse<null>>('/user/addAdminUser', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-账号-查看
export const viewAdminUser = (params: ViewAdminUserParams) =>
  request.post<BaseResponse<ViewAdminUserResponseData>>('/user/viewAdminUser', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-账号-编辑
export const editAdminUser = (params: EditAdminUserParams) =>
  request.post<BaseResponse<null>>('/user/editAdminUser', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-账号-删除
export const deleteUser = (params: DeleteUserParams) =>
  request.post<BaseResponse<null>>('/user/deleteUser', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-账号-启用/禁用
export const changeUserStatus = (params: ChangeUserStatusParams) =>
  request.post<BaseResponse<null>>('/user/changeUserStatus', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-账户-分页列表
export const getAdminListByPage = (params: GetAdminListByPageParams) =>
  request.post<BaseResponse<GetAdminListByPageResponseData>>('/user/getAdminListByPage', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });

// 管-账户-下拉列表
export const getUserDropdownList = () =>
  request.post<BaseResponse<UserDropdownItem[]>>('/user/getUserDropdownList');

// ---------------------- 当前登录用户信息 ----------------------

// 个管-登录帐号-查看
export const getLoginUserInfo = () =>
  request.post<BaseResponse<GetLoginUserInfoResponseData>>('/user/getLoginUserInfo');

// 个管-登录帐号-编辑
export const editLoginUserInfo = (params: FormDataParams) =>
  request.post<BaseResponse<null>>('/user/editLoginUserInfo', params, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });
